﻿//
// *************************************************************************************
// WP-Framework
//
// Developed by 
// Lukas Kretschmar (lkretschmar.dev@bluewin.ch)
//
// Switzerland, Copyright (c) 2013 lkretschmar
// This content is released under the MIT License (http://opensource.org/licenses/MIT).
//     
// *************************************************************************************
//
//


using System.Linq.Expressions;
using KretschIT.WP_Fx.EasyMoq.Extensions;
using KretschIT.WP_Fx.EasyMoq.Matchers;
using System.Collections.Generic;
using KretschIT.WP_Fx.Core.Validation;

namespace KretschIT.WP_Fx.EasyMoq.Calls.Collections.Items
{
    internal abstract class SetupItem<TExecutable> : CallItem, ISetupItem
    {
        public SetupItem(MethodCallExpression call, TExecutable executable)
            : base(call)
        {
            It.IsNotNull(() => executable);

            this.Executable = executable;
            this.Matcher = call.Arguments.ToMatchers();
        }

        protected TExecutable Executable { get; private set; }
        protected IEnumerable<IMatcher> Matcher { get; private set; }

        protected override bool HasSameArguments(MethodCallExpression methodCall)
        {
            var args = methodCall.Arguments.ToArguments();
            return this.Compare(this.Matcher, args);
        }

        public int Calls { get; private set; }

        protected void IncrementCallCounter()
        {
            this.Calls++;
        }
    }
}
